<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>列表</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/list.css">
</head>
<body>
    <div class="nav">
        <img src="../img/logo.png" alt="">
        <span class="title">TQ02博客系统</span>
        <span class="spacer"></span>
        <a href="write.html">写博客</a>
        <a href="../logout">退出</a>
        <a href="./cancel.html">销户</a>
    </div>

    <div class="container">
        <div class="left">
            <img src="../img/头像.jpg" alt="">
            <h3></h3>
            <div style="margin-bottom: 10px;margin-top: 10px">
                <span>文章</span>
            </div>
            <div class="counter">
                <span></span>
            </div>
        </div>
        <div class="right">   
            <div class="blog">
<!--                <div class="blog-title">第一篇博客</div>-->
<!--                <div class="data">2021-06-02</div>-->
<!--                 <div class="desc">-->
<!--                  w1ixhn1-->
<!--                </div>-->
<!--                 <a href="content.html?blogId=1" class="detail">查看全文 &gt;&gt;</a>-->
            </div>
        </div>

    </div>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/app.js"></script>
    <script>
       function getBlogs() {
       $.ajax({
        type:'get',
        url:'../blog',
        success:function(body){
            let container=document.querySelector('.blog');
            var num=0;
            for(let blog of body){
                //装标题
                let blogDiv=document.createElement('div');
                blogDiv.className='blog-title';
                blogDiv.innerHTML=blog.title;
                container.appendChild(blogDiv);
                //装日期
                let dataDiv=document.createElement('div');
                dataDiv.className='data';
                dataDiv.innerHTML=blog.postTime;
                container.appendChild(dataDiv);
                //装摘要信息
                let descDiv = document.createElement('div');
                descDiv.className = 'desc';
                descDiv.innerHTML = blog.content;
                container.appendChild(descDiv);
                //构造查看全文按钮
                let a=document.createElement("a");
                a.href="content.html?blogId=?"+blog.blogId;
                a.className='detail';
                a.innerHTML='查看全文 &gt;&gt';
                container.appendChild(a);
                num++;
            }
            let h3=document.querySelector('.counter span');
            h3.innerHTML=num;
        }
       });
    }
    getBlogs();

       function getUser(){
           $.ajax({
               type:'get',
               url:'../user',
               success:function (body){
                   let h3=document.querySelector('.left h3');
                   h3.innerHTML=body.username;
               }
           })
       }
       getUser();
       checkLogin();
    </script>


</body>
</html>













